﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XMLTrays
{
    public partial class XMLInboxConfigControl : Form
    {
        private XMLInbox _inbox;
        public XMLInboxConfigControl(XMLInbox inbox)
        {
            InitializeComponent();
            _inbox = inbox;
            textBoxName.Text = _inbox._concreteName;
            textBoxDirectory.Text = _inbox.folder;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = xmlFolderBrowserDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                _inbox.folder = xmlFolderBrowserDialog.SelectedPath;
                textBoxDirectory.Text = _inbox.folder;
            }
            
        }


        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool validName = textBoxName.Text != "";
            /*bool validPath = (xmlFolderBrowserDialog.SelectedPath != "" && Directory.Exists(xmlFolderBrowserDialog.SelectedPath));
            validPath |= (textBoxDirectory.Text != "" && Directory.Exists(textBoxDirectory.Text));*/
            bool validPath = (textBoxDirectory.Text != "" && Directory.Exists(textBoxDirectory.Text));

            if (validName && validPath)
            {
                _inbox.folder = textBoxDirectory.Text;
                _inbox.setConcreteInboxName(textBoxName.Text);
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Por favor ingrese una ubicación y/o nombre válidos.");
            }

        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
